fix: safely parse portal URL hash params to prevent crash#26910
Conversation
|
You have used all of your free Bugbot PR reviews. To receive reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial. |
WalkthroughThe change introduces a 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@apps/portal/src/app.js`:
- Around line 29-37: In safeJSONParse, replace the incorrect JSON.Parse call
with the correct JSON.parse to avoid the TypeError and allow valid JSON to
parse; update the return statement inside the try block to call
JSON.parse(value) (leaving fallback behavior and the warning in the catch
unchanged) and run a quick smoke test to confirm valid URL JSON now returns
parsed objects from safeJSONParse.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 922cbdf1-8266-4144-8353-41bdb1ca2586
📒 Files selected for processing (1)
apps/portal/src/app.js
7ef1a87 to
9d8a4cf
Compare
closes TryGhost#26399 `fetchQueryStrData()` parses several preview hash params with `JSON.parse()` (`button`, `name`, `isFree`, `isMonthly`, `isYearly`, `signupCheckboxRequired`, `disableBackground`, `transistorPortalSettings`). A malformed value (e.g. `#/portal/preview?button={INVALID`) threw a `SyntaxError`: on initial load this was swallowed by `initSetup()` and left the widget unrendered, and on the `hashchange` path it rejected uncaught inside `updateStateForPreviewLinks()`. This code only runs in Portal preview mode (the Admin settings-preview iframe, or a hand-crafted `#/portal/preview` link), so a bad hash should never interrupt rendering. Wrapped the parse in `fetchPreviewData()` — the single boundary both paths go through — in a try/catch that reports the error to Sentry and renders without preview data. Added regression tests for the malformed and valid hashes.
9d8a4cf to
587286c
Compare
|
Hey @Rohit7241, I made some adjustments. We have stayed away from using |
🐛 Fixed portal URL hash parsing to prevent crash
closes #26399
The previous implementation of parsing URL hash parameters could
throw errors if the hash was malformed or missing. This change
introduces a safe JSON parse utility that ensures invalid or empty
hashes do not crash the portal. This improves stability and prevents
unexpected runtime errors for users navigating with unusual URLs.